AC_INIT([gltest], [0.0.0])
AC_CONFIG_AUX_DIR([acaux])
AC_CONFIG_MACRO_DIR([m4])
AM_INIT_AUTOMAKE

: ${CXXFLAGS:=-Wall -std=gnu++20}

AC_PROG_CXX

AC_SUBST([fontsdir], ['${pkgdatadir}/fonts'])
AC_SUBST([texturesdir], ['${pkgdatadir}/textures'])
AC_SUBST([shadersdir], ['${pkgdatadir}/shaders'])
AC_SUBST([modelsdir], ['${pkgdatadir}/models'])

# --enable-debug
AC_ARG_ENABLE(
    [debug],
    AS_HELP_STRING([--enable-debug], [Enable debug @<:@default=yes@:>@]),
    [glt_enable_debug=${enableval}],
    [glt_enable_debug=yes]
)

AS_CASE(
    [${glt_enable_debug}],
    [yes], [glt_debug_flags='-g -O0 -DGLT_DEBUG'],
    [no],  [glt_debug_flags='-O2 -DNDEBUG'],
    [AC_MSG_ERROR([glt_enable_debug: wrong value: ${glt_enable_debug}])]
)

# --enable-gprof
AC_ARG_ENABLE(
    [gprof],
    AS_HELP_STRING([--enable-gprof], [Enable gprof compile flags @<:@default=no@:>@]),
    [glt_enable_gprof=${enableval}],
    [glt_enable_gprof=no]
)

AS_CASE(
    [${glt_enable_gprof}],
    [yes], [glt_gprof_flags='-pg'; glt_gprof_libs='-pg'],
    [no],  [glt_gprof_flags=''; glt_gprof_libs=''],
    [AC_MSG_ERROR([glt_enable_gprof: wrong value: ${glt_enable_gprof}])]
)

#
AS_CASE(
    [${host}],
    [*-mingw32], [glt_static_gcc_ldflags='-static-libgcc -static-libstdc++'],
    [glt_static_gcc_ldflags='']
)

AC_SUBST([GLT_CFLAGS], ["$glt_debug_flags $glt_gprof_flags"])
AC_SUBST([GLT_LDFLAGS], ["$glt_static_gcc_ldflags"])
AC_SUBST([GLT_LIBS], ["$glt_gprof_libs"])

PKG_CHECK_MODULES([WTK], [wtk])

# glslc
AC_MSG_CHECKING([glslangValidator])
AC_PATH_PROG([GLSLC], [glslangValidator])
AC_MSG_RESULT([$GLSLC])
AC_ARG_VAR([GLSLC], [glsl validator])

AC_CONFIG_FILES([ \
  Makefile \
  src/Makefile \
  data/Makefile \
  data/fonts/Makefile \
  data/textures/Makefile \
  data/models/Makefile \
  data/shaders/Makefile \
  data/shaders/glslc \
])
AC_OUTPUT
